import sqlite3

conn = sqlite3.connect('sensor_data.db')
cursor = conn.cursor()

# 创建表
cursor.execute('''
CREATE TABLE IF NOT EXISTS measurements (
    id INTEGER PRIMARY KEY AUTOINCREMENT,
    name TEXT,
    value REAL
)
''')

# 插入一些测试数据
data = [
    ('temperature', 23.5),
    ('humidity', 45.2),
    ('pressure', 1012.3),
    ('temperature', 24.1),
    ('humidity', 44.8),
    ('pressure', 1011.9),
    ('temperature', 22.9),
    ('humidity', 46.0),
    ('pressure', 1013.1)
]

cursor.executemany('INSERT INTO measurements (name, value) VALUES (?, ?)', data)
conn.commit()
conn.close()